package com.example.list;

import android.app.Dialog;
import android.content.Context;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

public class EditTextDialog extends Dialog {
    Context mContext;
    private TextView title;
    private LinearLayout ll_money;
    EditTextListener editTextListener;
    private TextView tvNameMoney;
    private TextView tvMoney;
    private TextView tvNameBank;
    private TextView tvBank;
    private TextView tvNamePwd;
    private EditText etPwd;
    private TextView dialogCancle;
    private TextView dialogConfirm;

    String money;
    String bank;

    public EditTextDialog(@NonNull Context context,int type) {
        super(context, R.style.CustomDialog);
//        设置点击dialog外部区域，弹框消失
        setCanceledOnTouchOutside(true);
        this.mContext = context;
        initView();
        registListener();
        setType(type);
    }



    //初始化
    public void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_dj_transfer_dialog, null);
        title = (TextView) view.findViewById(R.id.title);
        ll_money = (LinearLayout) view.findViewById(R.id.ll_money);
        tvNameMoney = (TextView) view.findViewById(R.id.tv_name_money);
        tvMoney = (TextView) view.findViewById(R.id.tv_money);
        tvNameBank = (TextView)view. findViewById(R.id.tv_name_bank);
        tvBank = (TextView) view.findViewById(R.id.tv_bank);
        tvNamePwd = (TextView) view.findViewById(R.id.tv_name_pwd);
        etPwd = (EditText) view.findViewById(R.id.et_pwd);
        dialogCancle = (TextView) view.findViewById(R.id.dialog_cancle);
        dialogConfirm = (TextView) view.findViewById(R.id.dialog_confirm);
        super.setContentView(view);
    }


    /**
     * @param type 设置对应类型
     *             0 对应转入
     *             1 对应转出
     */
    private void  setType(int type){

        if (type==0) {
            title.setText("转账确认");
            ll_money.setVisibility(View.VISIBLE);
            tvNameMoney.setText("转入金额");
            tvNameBank.setText("转入银行");
            tvNamePwd.setText("银行密码");
            etPwd.setHint("请输入银行密码");
        }else if(type ==1) {
            title.setText("转账确认");
            ll_money.setVisibility(View.VISIBLE);
            tvNameMoney.setText("转出金额");
            tvNameBank.setText("转出银行");
            tvNamePwd.setText("资金密码");
            etPwd.setHint("请输入资金密码");
        }else if (type==2){
            title.setText("余额查询");
            ll_money.setVisibility(View.GONE);
            tvNameBank.setText("银行账户");
            tvNamePwd.setText("银行密码");
            etPwd.setHint("请输入银行密码");
        }
    }

    /**
     * @param money 金额
     * @param bank 银行名称
     */
    void setData(String money,String bank){
        tvMoney.setText(money);
        tvBank.setText(bank);
    }
    void setBank(String bank){
        tvBank.setText(bank);
    }
    public EditTextDialog setTile(String s) {
        title.setText(s);
        return this;
    }
    private void registListener() {
        dialogConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content=etPwd.getText().toString().trim();
                editTextListener.getEtContent(content);
            }
        });
    }

    //确定键监听器
    public void setOnSureListener(EditTextListener editTextListener) {
        this.editTextListener=editTextListener;
    }

    //取消键监听器
    public void setOnCanlceListener(View.OnClickListener listener) {
        dialogCancle.setOnClickListener(listener);
    }

  interface   EditTextListener{
        void getEtContent(String content);
  }
}
